package com.green.system.common;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Green
 * @Date: 2021/11/01/22:20
 * @Description:
 */


/**
* @Description: 当实现了ApplicationContextAware之后，IOC容器初始化时会回调setApplicationContext把IOC容器对象转到里面
* @Param:
* @return: IOC容器对象
* @Author: Green
* @Date: 2021/11/1
*/


//对象不在容器里就没办法用
@Component
public class AppUtils implements ApplicationContextAware {

    private static ApplicationContext context;

    public static ApplicationContext getContext(){
        return context;
    }
    
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
}
